//JavaScript Framework 2.0 Code
try {
	Type.registerNamespace('com.yonyou.ncmm_pac_pda.SapplyScanController');
	com.yonyou.ncmm_pac_pda.SapplyScanController = function() {
		com.yonyou.ncmm_pac_pda.SapplyScanController.initializeBase(this);
		this.initialize();
	}

	function com$yonyou$ncmm_pac_pda$SapplyScanController$initialize() {
		//you can programing by $ctx API
		//get the context data through $ctx.get()
		//set the context data through $ctx.push(json)
		//set the field of the context through $ctx.put(fieldName, fieldValue)
		//get the parameter of the context through $ctx.param(parameterName)
		//Demo Code:
		//    var str = $ctx.getString();      //获取当前Context对应的字符串
		//    alert($ctx.getString())          //alert当前Context对应的字符串
		//    var json = $ctx.getJSONObject(); //获取当前Context，返回值为json
		//    json["x"] = "a";        //为当前json增加字段
		//    json["y"] = [];           //为当前json增加数组
		//    $ctx.push(json);            //设置context，并自动调用数据绑定
		//    
		//    put方法需手动调用databind()
		//    var x = $ctx.get("x");    //获取x字段值
		//    $ctx.put("x", "b");     //设置x字段值
		//    $ctx.put("x", "b");     //设置x字段值
		//    $ctx.databind();            //调用数据绑定才能将修改的字段绑定到控件上
		//    var p1 = $param.getString("p1");   //获取参数p2的值，返回一个字符串
		//    var p2 = $param.getJSONObject("p2");   //获取参数p3的值，返回一个JSON对象
		//    var p3 = $param.getJSONArray("p3");   //获取参数p1的值，返回一个数组

		//your initialize code below...

	}
	var isEdit=false;
	var editVbatchcode="";
	function com$yonyou$ncmm_pac_pda$SapplyScanController$evaljs(js) {
		eval(js)
	}
	//回退
	function com$yonyou$ncmm_pac_pda$SapplyScanController$close(sender, args) {
		$view.close();
	}
	//菜单
	function opendropmenu(sender, args) {
		SapplyUtil.openDropDownListForScan("btn_menu");
	}
	//加载
	function com$yonyou$ncmm_pac_pda$SapplyScanController$onload(sender, args) {
		var row = $param.getJSONObject("row");
		row = NCMMPubUtil.htmlspecialjson2UI(row);
		// 如果不存在数据表则先创建
		NCMMPubUtil.createTable(SapplyScanVO);
		if(!(row == null || row == "")) {
			var json = {};
			json = row;	
			editVbatchcode=json.vbatchcode;	
			//$alert("json="+$jsonToString(json));
			if("Y"==json.iswast){
			$id("panel18").set("display","block");
			}
			else{
			$id("panel18").set("display","none");
			}
			$ctx.push(json);
			$ctx.dataBind();
		};
		if(NCMMPubUtil.isNotEmpty($param.getJSONObject("isEdit"))){
			isEdit=$param.getJSONObject("isEdit");
			
		}
	}
	//扫码
	function com$yonyou$ncmm_pac_pda$SapplyScanController$doscan(sender, args) {
		var listJson = $ctx.getJSONObject();
		//$alert(listJson);
		if(NCMMPubUtil.isEmpty(listJson.pk_head)) {
			$alert("请先指定单据！");
			return;
		}
		$scanner.open({
			bindfield: "marbarcode",
			callback: "marScanBack()"
		});
	}

	function marScanBack() {
		var marbarcode = $ctx.getString("marbarcode");
		if (marbarcode != null && marbarcode != "") {
		 // 扫描的是物料码
		 $id("textbox0").set("value", marbarcode);
		 $ctx.dataBind();
		 }
		parseMarCode(marbarcode);
		$id("textbox0").set("value", null);
		
	}
	//解析
	function parseMarCode(marbarcode) {
		var listJson = $ctx.getJSONObject();
		if(NCMMPubUtil.isEmpty(listJson.pk_head)) {
			$alert("请先指定单据号！");
			return;
		}
		if("Y"==listJson.iswast&&NCMMPubUtil.isEmpty(listJson.cwastewarehouseid)){
		   $alert("请先指定报废仓库！")
		   return;
		}
		if(NCMMPubUtil.isEmpty(marbarcode)) {
			$alert("物料码为空！");
			return;
		}
		var marJson = NCMMBarcodeParseUtil.parseMaterialBar(marbarcode);
		//$alert("marJson="+$jsonToString(marJson));
		var marID = marJson.pk_material;
		if(NCMMPubUtil.isEmpty(marID)) {
			$alert(marJson.failmsg);
			return;
		}
		if(!NCMMPubUtil.isEmpty(listJson.pk_item)) {
			var wheresql = " where pk_item='" + listJson.pk_item + "'";
			NCMMPubUtil.queryVO(SapplyVO, wheresql, function(data) {
				if(typeof(data) == 'undefined' || data == null || data.length == 0) {
					return;
				} else {
					//2 打开扫描记录编辑界面
					var vos = eval(data);
					  vos = NCMMPubUtil.htmlspecialjsonarray2UI(vos);
					//$alert("扫描结果为=" + $jsonToString(vos));
					if(vos != null && vos.length > 0) {
						listJson = vos[0];
					}
				}
			});
		}
	
		if(NCMMPubUtil.isEmpty(listJson.pk_item) || marID != listJson.cmaterialvid || marJson.vbatchcode != listJson["vbatchcode"]) {
			var vo = queryScanInfo(marID, marJson.vbatchcode, listJson.pk_head);
			if(NCMMPubUtil.isEmpty(vo)) {
				$alert("扫描物料" + marJson.code + "不在对应的单据" + listJson["vbillcode"] + "中");
				return;
			}
			listJson = vo;
		}
		
		//扫描的批次号与单据本身的批次号均不空且不同为true
		var isNotEditAndBatchcodeDif=!isEdit&&NCMMPubUtil.isNotEmpty(listJson["vbatchcode"]) && NCMMPubUtil.isNotEmpty(marJson.vbatchcode) && listJson["vbatchcode"] != marJson.vbatchcode;
		
		//扫描记录编辑前的批次号与扫描的批次号不同为ture
		var isEditScanBatchCodeDifPreCode=isEdit&&NCMMPubUtil.isNotEmpty(editVbatchcode) && NCMMPubUtil.isNotEmpty(marJson.vbatchcode) &&editVbatchcode != marJson.vbatchcode
		//扫描的批次号与订单上的批次号不同时为true
		var isEditAndBatchCodeDif=isEditScanBatchCodeDifPreCode&&NCMMPubUtil.isNotEmpty(listJson["vbatchcode"]) && NCMMPubUtil.isNotEmpty(marJson.vbatchcode) &&listJson["vbatchcode"] != marJson.vbatchcode
		//非修改界面的扫码：当扫描的批次号与单据的批次号不同时提示变更；
		//修改界面的扫码：当扫描的批次号与之前的保存的批次号不同且与单据的批次号不同时提示变更；
		if(isNotEditAndBatchcodeDif||isEditAndBatchCodeDif) {		
				var isReplace = $confirm("扫描物料" + marJson.code + "的批次号和单据" + listJson["vbillcode"] + "的批次号不符，是否变更批次号?")
				if(isReplace == true || isReplace == "true") {
					listJson["vnotebody"] = "批次号由" + listJson["vbatchcode"] + "变更为" + marJson.vbatchcode;
				} else {
					return;
				}			
		}
		
		//listJson["vbarcode"] = "";
		if(NCMMPubUtil.isNotEmpty(marJson.vbatchcode)) {
			listJson["vbatchcode"] = marJson.vbatchcode;
		}
		listJson["vserialcode"] = marJson.vserialcode;
		var num = 1;
		var vchangerate = listJson["vchangerate"];
		var nastnum = NCMMPubUtil.getAstnum(1, vchangerate);
		if(NCMMPubUtil.isNotEmpty(marJson.nnum)){
		   num=marJson.nnum;
		   nastnum=NCMMPubUtil.getAstnum(num, vchangerate);
	    }else if(NCMMPubUtil.isNotEmpty(marJson.nassistnum)){
		   nastnum=marJson.nassistnum;
		   num=NCMMPubUtil.getNum(nastnum, vchangerate);
	   }
		var unitBitNum = NCMMPubUtil.getUnitBitnumber(listJson["cunitid"]);
		if(!NCMMPubUtil.isEmpty(unitBitNum)) {
		    if(num == null || num == "") {
                 num += "00.00000";
            } else {
                 num = parseFloat(num);
            }			
		    num = num.toFixed(unitBitNum);
		}
		var astunitBitNum = NCMMPubUtil.getUnitBitnumber(listJson["castunitid"]);
		if(!NCMMPubUtil.isEmpty(astunitBitNum)) {
		    if(nastnum == null || nastnum == "") {
                 nastnum += "00.00000";
            } else {
                 nastnum = parseFloat(nastnum);
            }
			nastnum = nastnum.toFixed(astunitBitNum);
		}
		if(listJson["nnum"] <0){
		listJson["nscannum"] = -num;
		listJson["nscanastnum"] = -nastnum;
		}
		else{
		listJson["nscannum"] = num;
		listJson["nscanastnum"] = nastnum;
		}
		listJson["pk_scan"] = getScanPK();
		NCMMPubUtil.insertVO(SapplyScanVO, listJson);
		SapplyUtil.updateScanedNum(listJson.pk_item);
		$ctx.push(listJson);
		$ctx.dataBind();

	}

	function queryScanInfo(marID, vbatchcode, pk_head) {
		var vo = {};
		var whereSql = " where pk_head='" + pk_head + "' and cmaterialvid='" + marID + "'";
		NCMMPubUtil.queryVO(SapplyVO, whereSql, function(data) {
			if(typeof(data) == 'undefined' || data == null || data.length == 0) {
				vo = null;
			} else {
				//2 打开扫描记录编辑界面
				var vos = eval(data);
				  vos = NCMMPubUtil.htmlspecialjsonarray2UI(vos);
				//$alert("扫描结果为=" + $jsonToString(vos));
				if(vos != null && vos.length > 0) {
					if(vos.length == 1) {
						vo = vos[0];
					} else {
						vo = getScanVO(vos, vbatchcode);
					}
				} else {
					vo = null;
				}
			}
		});
		return vo;
	}

	function getScanVO(vos, vbatchcode) {
		//数量满足批次号为空的行，或当扫描物料的批次号为空时，数量不满足的行
		var result1 = [];
		//数量不满足批次号相同的行
		var result2 = [];
		//数量不满足批次号为空的行
		var result3 = [];
		//数量满足批次号不一致的行
		var result4 = [];
		//数量不满足批次不一致的行
		var result5 = [];
		var vo = {};
		for(var i = 0; i < vos.length; i++) {
			//if(!NCMMPubUtil.isEmpty(pk_item) && vos[i].pk_item == pk_item) {
			//vo = vo[i];
			//}
			//数量满足
			if(vos[i].nnum > vos[i].nscanednum) {
				if(NCMMPubUtil.isEmpty(vbatchcode)) {
					return vos[i];
				} else if(vbatchcode == vos[i].vbatchcode) {
					return vos[i];
				} else if(NCMMPubUtil.isEmpty(vos[i].vbatchcode)) {
					result1.push(vos[i]);
				} else {
					result4.push(vos[i]);
				}
			}
			//数量不满足
			else {
				if(NCMMPubUtil.isEmpty(vbatchcode)) {
					result1.push(vos[i]);
				} else if(vbatchcode == vos[i].vbatchcode) {
					result2.push(vos[i]);
				} else if(NCMMPubUtil.isEmpty(vos[i].vbatchcode)) {
					result3.push(vos[i]);
				} else {
					result5.push(vos[i]);
				}
			}
		}
		if(result1.length > 0) {
			return result1[0];
		} else if(result2.length > 0) {
			return result2[0];
		} else if(result3.length > 0) {
			return result3[0];
		} else if(result4.length > 0) {
			return result4[0];
		} else if(result5.length > 0) {
			return result5[0];
		} else {
			return null;
		}
	}

	function getScanPK() {
		var date = new Date().getTime();
		var pk = "4455" + date.toString() + "111";
		return pk;
	}
	//保存
	function com$yonyou$ncmm_pac_pda$SapplyScanController$saveScanInfo(sender, args) {
		var json = $ctx.getJSONObject();
		if(json.nscannum == null || json.nscannum == 0 || json.nscannum == "0") {
			$alert("扫描主数量不能为空或0！")
			return;
		}
		if(json.nscanastnum == null || json.nscanastnum == 0 || json.nscanastnum == "0") {
			$alert("扫描数量不能为空或0！")
			return;
		}
		if(!$.isNumeric(json.nscannum) || !$.isNumeric(json.nscanastnum)) {
			$alert("数量输入不合法！")
			return;
		}
		if("Y"==json.iswast&&NCMMPubUtil.isEmpty(json.cwastewarehouseid)){
		   $alert("报废仓库不能为空！")
		   return;
		}
		json=NCMMPubUtil.htmlspecialjson2UI(json);
		var isSuccess = doSave(json);
		if(isSuccess == true) {
			$toast("保存成功！");
		}
	}
	//保存按钮保存或提交前保存
	function doSave(json) {		
		var billBatchCode = getBillBatchCode(json["pk_item"]);
		if(NCMMPubUtil.isEmpty(json["pk_scan"])) {
			if(!NCMMPubUtil.isEmpty(json["vbatchcode"]) && !NCMMPubUtil.isEmpty(billBatchCode) && json["vbatchcode"] != billBatchCode) {
				var isReplace = $confirm("扫描物料" + json["cmaterialvid_code"] + "的批次号和单据" + json["vbillcode"] + "的批次号不符，是否变更批次号?")
				if(isReplace == true || isReplace == "true") {
					json["vbnote"] = "批次号由" + billBatchCode + "变更为" + json["vbatchcode"];
				} else {
					return false;
				}
			}
			json["pk_scan"] = getScanPK();
			NCMMPubUtil.insertVO(SapplyScanVO, json);
			$ctx.push(json);
			$ctx.dataBind();
		} else {
			var oldBatchCode = getOldScanBatchCode(json["pk_scan"]);
			if(!NCMMPubUtil.isEmpty(json["vbatchcode"])) {
				if(!NCMMPubUtil.isEmpty(billBatchCode) && json["vbatchcode"] != oldBatchCode && json["vbatchcode"] != billBatchCode) {
					var isReplace = $confirm("扫描物料" + json["cmaterialvid_code"] + "的批次号和单据" + json["vbillcode"] + "的批次号不符，是否变更批次号?")
					if(isReplace == true || isReplace == "true") {
						json["vbnote"] = "批次号由" + billBatchCode + "变更为" + json["vbatchcode"];
					} else {
						return false;
					}
				} else if(!NCMMPubUtil.isEmpty(billBatchCode) && json["vbatchcode"] != oldBatchCode && json["vbatchcode"] == billBatchCode) {
					json["vbnote"] = "";
				}
			} else {
				json["vbnote"] = "";
			}
			NCMMPubUtil.updateVO(SapplyScanVO, json);
		}
		//更新调拨订单列表增加扫描数量 		
		SapplyUtil.updateScanedNum(json.pk_item);
		return true;
	}
	function getOldScanBatchCode(pk_scan) {
		var sql = " where pk_scan='" + pk_scan + "'";
		var batchcode = "";
		NCMMPubUtil.queryVO(SapplyScanVO, sql, function(data) {
			if(typeof(data) == 'undefined' || data == null || data.length == 0) {
				return;
			} else {
				//2 打开扫描记录编辑界面
				var vos = eval(data);
				  vos = NCMMPubUtil.htmlspecialjsonarray2UI(vos);
				if(vos != null && vos.length > 0) {
					batchcode = vos[0].vbatchcode;
				}
			}
		});
		return batchcode;
	}
	function getBillBatchCode(pk_item) {
		var sql = " where pk_item='" + pk_item + "'";
		var batchcode = "";
		NCMMPubUtil.queryVO(SapplyVO, sql, function(data) {
			if(typeof(data) == 'undefined' || data == null || data.length == 0) {
				return;
			} else {
				//2 打开扫描记录编辑界面
				var vos = eval(data);
				  vos = NCMMPubUtil.htmlspecialjsonarray2UI(vos);
				if(vos != null && vos.length > 0) {
					batchcode = vos[0].vbatchcode;
				}
			}
		});
		return batchcode;
	}
	//提交
	function com$yonyou$ncmm_pac_pda$SapplyScanController$doCommit(sender, args) {
       
		var json = $ctx.getJSONObject();
		var stordoc = $cache.read("defaultstordoc");
        if(NCMMPubUtil.isEmpty(stordoc)&&NCMMPubUtil.isEmpty(json.cwarehouseid)) {
            $alert("默认仓库不能为空，请设置！");
            return;
        }
		if(NCMMPubUtil.isEmpty(json.pk_item)) {
			$alert("无扫描数据，不能提交！");
			return;
		}
		if(json.nscannum == null || json.nscannum == 0 || json.nscannum == "0") {
			$alert("扫描主数量不能为空或0！")
			return;
		}
		if(json.nscanastnum == null || json.nscanastnum == 0 || json.nscanastnum == "0") {
			$alert("扫描数量不能为空或0！")
			return;
		}
		if(!$.isNumeric(json.nscannum) || !$.isNumeric(json.nscanastnum)) {
			$alert("数量输入不合法！")
			return;
		}
		if("Y"==json.iswast&&NCMMPubUtil.isEmpty(json.cwastewarehouseid)){
		   $alert("报废仓库不能为空！")
		   return;
		}
		json=NCMMPubUtil.htmlspecialjson2UI(json);
		var isSuccess = doSave(json);
		if(isSuccess == false) {
			return;
		}
		var scanNum = SapplyUtil.getScanVOCount(json.pk_item);
		if(scanNum > 1) {
			$js.hideLoadingBar();
			$alert("当前单据行有其他扫描记录，请全部选中后再提交！");
			return;
		}
		var sql = " where pk_scan='" + json.pk_scan + "'";
		var vo = {};
		NCMMPubUtil.queryVO(SapplyScanVO, sql, function(scanData) {
			if(typeof(scanData) == 'undefined' || scanData == null || scanData.length == 0) {
				return;
			}
			var vos = eval(scanData);
			  vos = NCMMPubUtil.htmlspecialjsonarray2UI(vos);
			vo = vos[0];
		});
		if(NCMMPubUtil.isEmpty(vo)) {
			$alert("当前扫描记录已经被删除，不能提交！")
			return;
		}
		//组件提交billinfos 
		var head = {};
		head["pk_head"] = vo.pk_head;		
		head["ts_h"] = vo.hts;
		var item = {};
		if(NCMMPubUtil.isNotEmpty(vo.cwarehouseid)){
			item["cwarehouseid"] =vo.cwarehouseid;
		}
		else{
			item["cwarehouseid"] = $stringToJSON(stordoc).pk_stordoc;
		}
		item["cwastewarehouseid"]=vo.cwastewarehouseid;
		item["pk_item"] = vo.pk_item;
		item["cmaterialvid"] = vo.cmaterialvid;
		item["castunitid"] = vo.castunitid;
		item["nscannum"] = vo.nscannum;
		item["nscanastnum"] = vo.nscanastnum;
		item["vbatchcode"] = vo.vbatchcode;
		item["bts"] = vo.bts;
		item["vbnote"] = json.vbnote;	
		if(!NCMMPubUtil.isEmpty(vo.vserialcode) || !NCMMPubUtil.isEmpty(vo.cspaceid)) {
			var bbitem = {};
			//bbitem["pk_serialcode"] = vo.pk_serialcode;
			bbitem["vserialcode"] = vo.vserialcode;
			bbitem["nnum"] = vo.nscannum;
			bbitem["nassistnum"] = vo.nscanastnum;
			bbitem["clocationid"] = vo.cspaceid;
			var bbitems = [{
				"bbitem": bbitem
			}];
			item["bbitems"] = bbitems;
		}
		var items = [{
			"item": item
		}];
		var billinfo = {
			"head": head,
			"items": items
		};
		var billinfos = [{
			"billinfo": billinfo
		}];			
		var isSuccess = SapplyUtil.commitData(billinfos,json.pk_scan,function(data){	
		    //清空界面值
           doClear();		  		   
		});
	
	}
	/**
	 * 清空界面数据
     * @param {Object} sender
     * @param {Object} args
	 */
	function doClear(){
	   $ctx.put("vbarcode","");
	   $ctx.put("vbillcode","");
	   $ctx.put("iswast","");
	   $ctx.put("ctrantypeidname","");
	   $ctx.put("crowno","");
	   $ctx.put("cmaterialvid_code","");
	   $ctx.put("cmaterialvid_name","");
	   $ctx.put("materialspec","");
	   $ctx.put("materialtype","");
	   $ctx.put("vbatchcode","");
	   $ctx.put("vserialcode","");
	   $ctx.put("nassistnum","");
	   $ctx.put("nnum","");
	   $ctx.put("nscanastnum","");
	   $ctx.put("nscannum","");
	   $ctx.put("pk_scan","");
	   $ctx.put("cspaceid_name","");
	   $ctx.dataBind();
	}
	//编辑主数量，计算辅数量
	function com$yonyou$ncmm_pac_pda$SapplyScanController$calAstNum(sender, args) {
		var nn = args["newvalue"];
		if(NCMMPubUtil.isEmpty(nn)) {
			$ctx.put("nscanastnum", "");
			$ctx.dataBind();
			return;
		}
		if(nn == "-") {
			return;
		}
		if(!$.isNumeric(nn)) {
			$ctx.put("nscannum", args["oldvalue"]);
			$ctx.dataBind();
			return;
		}

		if(NCMMPubUtil.isBsBitnumber(nn, $ctx.getString("cunitid"))) {
			$ctx.put("nscannum", args["oldvalue"]);
			$ctx.dataBind();
			return;
		}
		$ctx.dataCollect();
		var nnum = $ctx.getString("nscannum");
		if(NCMMPubUtil.isEmpty(nnum)){
			//如果主数量输入为空 例如输入后不停后退至空 则辅数量为空返回
			$ctx.put("nscanastnum", "");
			$ctx.dataBind();
			return;
		}
		if(!$.isNumeric(nnum)) {
			$alert("扫描主数量输入不合法！");
			return;
		}
		var vchangerate = $ctx.getString("vchangerate");
		var nastnum = "";
		if(!NCMMPubUtil.isEmpty(nnum)) {
		        
			nastnum = NCMMPubUtil.getAstnum(nnum, vchangerate);
			var bitnum = NCMMPubUtil.getUnitBitnumber($ctx.getString("castunitid"));
			if(!NCMMPubUtil.isEmpty(bitnum)) {
				nastnum =NCMMPubUtil.decimalPrecision(nastnum,bitnum);
			}
			//$alert(nastnum);
			if(nastnum.toString() == "NaN") {
				$alert("数量输入不合法！");
				return;
			}
		}
		$ctx.put("nscanastnum", nastnum);
		$ctx.dataBind();
	}

	//编辑辅数量，计算主数量
	function com$yonyou$ncmm_pac_pda$SapplyScanController$calNum(sender, args) {
		var nn = args["newvalue"];
		if(NCMMPubUtil.isEmpty(nn)) {
			$ctx.put("nscannum", "");
			$ctx.dataBind();
			return;
		}
		if(nn == "-") {
			return;
		}
		if(!$.isNumeric(nn)) {
			$ctx.put("nscanastnum", args["oldvalue"]);
			$ctx.dataBind();
			return;
		}
		if(NCMMPubUtil.isBsBitnumber(nn, $ctx.getString("castunitid"))) {
			$ctx.put("nscanastnum", args["oldvalue"]);
			$ctx.dataBind();
			return;
		}
		$ctx.dataCollect();
		var nastnum = $ctx.getString("nscanastnum");
		if(NCMMPubUtil.isEmpty(nastnum)){
			//如果辅数量输入为空 例如输入后不停后退至空 则主数量为空返回
			$ctx.put("nscannum", "");
			$ctx.dataBind();
			return;
		}
		if(!$.isNumeric(nastnum)) {
			$alert("扫描数量输入不合法！");
			return;
		}
		var vchangerate = $ctx.getString("vchangerate");
		var nnum;
		if(!NCMMPubUtil.isEmpty(nastnum)) {		        
			nnum = NCMMPubUtil.getNum(nastnum, vchangerate);		    
			var bitnum = NCMMPubUtil.getUnitBitnumber($ctx.getString("cunitid"));
			if(!NCMMPubUtil.isEmpty(bitnum)) {
				nnum = NCMMPubUtil.decimalPrecision(nnum,bitnum);
			}
			//$alert(nnum);
			if(nnum.toString() == "NaN") {
				$alert("数量输入不合法！");
				return;
			}
		}
		$ctx.put("nscannum", nnum);
		$ctx.dataBind();
	}
	//物料码输入
	function com$yonyou$ncmm_pac_pda$SapplyScanController$inputMarCode(sender, args) {
		$ctx.dataCollect();
		var marbarcode = $ctx.getString("marbarcode");
		parseMarCode(marbarcode);
		$id("textbox0").set("value", null);
		$id("textbox0").focus();
	}

    function onEventClick_showSpaceRef(sender, args){
        var stordoc = $cache.read("defaultstordoc");
        if(stordoc == null || stordoc == "") {
            $alert("默认仓库不能为空，请设置！");
            return;
        }
         var stordoc = $cache.read("defaultstordoc");
		 var wheresql= " where pk_stordoc='" + $stringToJSON(stordoc).pk_stordoc + "'";		
       
        NCMMPubUtil.openRefPage("PDARACK", "cspaceid_name", "cspaceid", "pk_rack",wheresql);

    }
 //货位edit  
function com$yonyou$ncmm_pac_pda$SapplyScanController$spaceEdit(sender, args){
var rack = $ctx.getString("cspaceid_name");
		if(NCMMPubUtil.isEmpty(rack)) {
			$ctx.put("cspaceid_name", "");
			$ctx.put("cspaceid", "");
			$ctx.dataBind();
			return;
		}
		var wheresql = " where (code='" + rack + "' or name ='" + rack + "')";
		var stordoc = $cache.read("defaultstordoc");
		if(!NCMMPubUtil.isEmpty(stordoc)) {
			wheresql = wheresql + " and pk_stordoc='" + $stringToJSON(stordoc).pk_stordoc + "'";
		}
		getRackInfoByWhereSql(wheresql, rack,"cspaceid","cspaceid_name");
}
//货位Scan
function com$yonyou$ncmm_pac_pda$SapplyScanController$spaceScan(sender, args){
     $scanner.open({
			bindfield: "rack",
			callback: "rackScanBack()"
		});
}

	function rackScanBack() {
		var rack = $ctx.getString("rack");
		var wheresql = " where code='" + rack + "'";
		var stordoc = $cache.read("defaultstordoc");
		if(!NCMMPubUtil.isEmpty(stordoc)) {
			wheresql = wheresql + " and pk_stordoc='" + $stringToJSON(stordoc).pk_stordoc + "'";
		}
		getRackInfoByWhereSql(wheresql, rack,"cspaceid","cspaceid_name");
	}

	function getRackInfoByWhereSql(wheresql, rack,pkField,nameField) {
		if(NCMMPubUtil.isTableExist(RackVO) == false) {
			$alert("没有扫描货位【" + rack + "】记录，请更新货位数据，或检查当前扫描货位是否属于默认仓库！");
			$ctx.put(nameField, "");
			$ctx.put(pkField, "");
			$ctx.dataBind();
			return;
		}
		NCMMPubUtil.queryVO(RackVO, wheresql, function(data) {
			//2 打开扫描记录编辑界面
			if(NCMMPubUtil.isEmpty(data)) {
				$alert("没有扫描货位【" + rack + "】记录，请更新货位数据，或检查当前扫描货位是否属于默认仓库！");
				$ctx.put(nameField, "");
				$ctx.put(pkField, "");
				$ctx.dataBind();
				return;
			}
			var vos = eval(data);
			$ctx.put(nameField, vos[0].name);
			$ctx.put(pkField, vos[0].pk_rack);
			$ctx.dataBind();
		});
}
function showWastewarehouseRef(sender, args){
     var stockorg = $cache.read("defaultstockorg") ? $cache.read("defaultstockorg") : "";
		if(stockorg == "") {
			$alert("请先设置默认库存组织！");
			return;
		}
       var wheresql= "where gubflag='Y'";
		//打开指定参照界面
		 NCMMPubUtil.openRefPage("PDASTORDOC", "cwastewarehouseid_name", "cwastewarehouseid", "pk_stordoc",wheresql);


} com.yonyou.ncmm_pac_pda.SapplyScanController.prototype = {
    spaceScan : com$yonyou$ncmm_pac_pda$SapplyScanController$spaceScan,
    spaceEdit : com$yonyou$ncmm_pac_pda$SapplyScanController$spaceEdit,
		inputMarCode: com$yonyou$ncmm_pac_pda$SapplyScanController$inputMarCode,
		calAstNum: com$yonyou$ncmm_pac_pda$SapplyScanController$calAstNum,
		calNum: com$yonyou$ncmm_pac_pda$SapplyScanController$calNum,
		doCommit: com$yonyou$ncmm_pac_pda$SapplyScanController$doCommit,
		saveScanInfo: com$yonyou$ncmm_pac_pda$SapplyScanController$saveScanInfo,
		onload: com$yonyou$ncmm_pac_pda$SapplyScanController$onload,
		doscan: com$yonyou$ncmm_pac_pda$SapplyScanController$doscan,
		close: com$yonyou$ncmm_pac_pda$SapplyScanController$close,
		initialize: com$yonyou$ncmm_pac_pda$SapplyScanController$initialize,
		evaljs: com$yonyou$ncmm_pac_pda$SapplyScanController$evaljs
	};
	com.yonyou.ncmm_pac_pda.SapplyScanController.registerClass('com.yonyou.ncmm_pac_pda.SapplyScanController', UMP.UI.Mvc.Controller);
} catch(e) {
	$e(e);
}